package com.dynamixsoftware.printershare.bjnp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;

public class BJNPMain {
	public static final int BJNP_CMD_PRINT = 1;
	public static final int BJNP_CMD_SCAN = 2;
	public static final int BJNP_PORT_3 = 8613;
	public static final int BJNP_PORT_4 = 8614;
	public static final int BJNP_PORT_PRINT = 8611;
	public static final int BJNP_PORT_SCAN = 8612;
	public static final int BJNP_RES_PRINT = 129;
	public static final int BJNP_RES_SCAN = 130;
	public static final int CMD_TCP_PRINT = 33;
	public static final int CMD_UDP_CLOSE = 17;
	public static final int CMD_UDP_DISCOVER = 1;
	public static final int CMD_UDP_GET_ID = 48;
	public static final int CMD_UDP_GET_STATUS = 32;
	public static final int CMD_UDP_PRINT_JOB_DETAILS = 16;
	public static final int CMD_UDP_SCAN_JOB = 50;
	private static int packet_id;

	public static int get_packet_id() {
		try {
			packet_id = 1 + packet_id;
			if (packet_id > 65535) {
				packet_id = 1;
			}
			int i = packet_id;
			return i;
		} finally {
		}
	}

	/* Error */
	public static BJNPCommand sendUDPCommand(BJNPCommand var0, InetSocketAddress var1, int var2) throws Exception {
		DatagramSocket var3 = new DatagramSocket();
		var3.setSoTimeout(var2);
		var0.seq_no = get_packet_id();
		byte[] var4 = var0.toPacket();
		var3.send(new DatagramPacket(var4, var4.length, var1.getAddress(), var1.getPort()));
		byte[] var5 = new byte[4096];
		long var6 = System.currentTimeMillis();

		BJNPCommand var9;
		do {
			long var15;
			int var8 = (var15 = System.currentTimeMillis() - var6 - (long) var2) == 0L ? 0 : (var15 < 0L ? -1 : 1);
			var9 = null;
			if (var8 >= 0) {
				break;
			}

			DatagramPacket var10;
			label32 : {
				label31 : {
					var10 = new DatagramPacket(var5, var5.length);

					try {
						var10.setLength(var5.length);
						var3.receive(var10);
						break label32;
					} catch (SocketTimeoutException var13) {
						;
					}
				}

				var9 = null;
				break;
			}

			var9 = BJNPCommand.fromPacket(var10.getData(), 0);
		} while (var9 == null || (255 & var9.dev_type) != 128 + (255 & var0.dev_type) || var9.seq_no != var0.seq_no);

		var3.close();
		return var9;
	}

}

/*
 * Location:
 * C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar
 * .jar
 * 
 * Qualified Name: com.dynamixsoftware.printershare.bjnp.BJNPMain
 * 
 * JD-Core Version: 0.7.0.1
 */